package cn.anecansaitin.whimsy.common.register;

import cn.anecansaitin.whimsy.Whimsy;
import cn.anecansaitin.whimsy.common.attachment.*;
import cn.anecansaitin.whimsy.common.capabilities.battle.BattleMode;
import cn.anecansaitin.whimsy.common.capabilities.ComboHandler;
import cn.anecansaitin.whimsy.common.capabilities.RockScepterManaStorage;
import cn.anecansaitin.whimsy.common.extension.comboSystem.Combo;
import cn.anecansaitin.whimsy.common.extension.comboSystem.SkillGraph;
import cn.anecansaitin.whimsy.common.extension.comboSystem.SkillPerformer;
import cn.anecansaitin.whimsy.common.extension.comboSystem.skills.rockSceptre.*;
import cn.anecansaitin.whimsy.test.register.TestItems;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.attachment.AttachmentType;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.NeoForgeRegistries;

import java.util.function.Supplier;

public class ModDataAttachments {
    public static final DeferredRegister<AttachmentType<?>> ATTACHMENT_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.ATTACHMENT_TYPES, Whimsy.MODID);

    public static final Supplier<AttachmentType<RockScepterManaStorage>> ROCK_SCEPTER_MANA_STORAGE = ATTACHMENT_TYPES.register("rock_scepter_mana_storage", () -> AttachmentType.serializable(RockScepterManaStorage::new).build());
    public static final Supplier<AttachmentType<ComboHandler>> ROCK_SCEPTER_COMBO_HANDLER = ATTACHMENT_TYPES.register("rock_scepter_combo_handler", () -> AttachmentType.builder(() -> {
        Attack0 attack0 = new Attack0();
        Attack1 attack1 = new Attack1();
        Attack2 attack2 = new Attack2();
        Attack3 attack3 = new Attack3();
        Attack4 attack4 = new Attack4();
        Attack5 attack5 = new Attack5();
        EarthQuake earthQuake = new EarthQuake();
        Attack6 attack6 = new Attack6();
        Attack7 attack7 = new Attack7();

        SkillGraph skillGraph = SkillGraph.build()
                .noPreDerive(attack0, 2)
                .noPreDerive(attack1, 1)
                .derive(attack0, attack0, 2)
                .derive(attack1, attack2, 1)
                .derive(attack2, attack3, 1)
                .derive(attack3, attack1, 1)
                .derive(attack3, attack4, 2)
                .derive(attack2, attack5, 2)
                .derive(attack5, earthQuake, 2)
                .derive(attack5, attack6, 1)
                .derive(attack6, attack7, 1)
                .create();

        return new ComboHandler(new Combo(skillGraph, new SkillPerformer()));
    }).build());
    public static final Supplier<AttachmentType<HandCannonMagazine>> HAND_CANNON_MAGAZINE = ATTACHMENT_TYPES.register("hand_cannon_magazine", () -> AttachmentType.serializable(HandCannonMagazine::new).build());
    public static final Supplier<AttachmentType<DoomfistSkill>> DOOMFIST_SKILL = ATTACHMENT_TYPES.register("doomfist_skill", () -> AttachmentType.serializable(DoomfistSkill::new).build());
    public static final Supplier<AttachmentType<ItemStackData>> HAND_CANNON_ARM = ATTACHMENT_TYPES.register("hand_cannon_arm", () -> AttachmentType.serializable(() -> new ItemStackData(new ItemStack(TestItems.HAND_CANNON_ARM.get()))).build());
    public static final Supplier<AttachmentType<ImpactData>> IMPACT_MOVEMENT_DATA = ATTACHMENT_TYPES.register("impact_movement_data", () -> AttachmentType.serializable(ImpactData::new).build());
    public static final Supplier<AttachmentType<SpeedData>> SPEED_DATA = ATTACHMENT_TYPES.register("speed_data", () -> AttachmentType.builder(SpeedData::new).build());
    //战斗模式数据
    public static final Supplier<AttachmentType<BattleMode>> BATTLE_MODE = ATTACHMENT_TYPES.register("battle_mode", () -> AttachmentType.serializable(BattleMode::new).copyOnDeath().build());
}
